<?php
require_once("inc.member.php");

$this_title="$vars[member_title] &raquo; ".replace_tag(__("<%title%> Withdrawal"), array("<%title%>"=>__($vars["ewallet_title"])));
$page_title=__("Transaction History");
$content_title=__("Transaction History");

$item_per_page=$vars["user_item_per_page"];

$r_status=array("pending","paid","cancelled");
$r_status_d=array("pending"=>__("Pending Payment"),"paid"=>__("Paid"),"cancelled"=>__("Cancelled"));
$r_payment=array("b","c","d","e","o");
$r_payment_d=array("b"=>__("Bank Transfer"), "c"=>__("Cash"), "d"=>__("Cheque"), "e"=>__("Credit Card"), "o"=>__("On-hold"));

//#####LIST WITHDRAWAL HISTORY#####
$count_sql="select count(*) from $db->member_withdraw where uid='$uid'";
$record_sql="select * from $db->member_withdraw where uid='$uid' order by cdate desc limit <%limit_start%>, <%limit%>";

$cur_page=$_GET["nav"];
$total_record=@mysql_result(mysql_query($count_sql), 0);
$total_page=ceil($total_record/$item_per_page);
$page=($cur_page? ($cur_page>$total_page? $total_page : ($cur_page<1? 1 : $cur_page)) : 1);
$limit_start=($page-1)*$item_per_page;
$nav_link=format_page($page, $total_page, 15);
$this_page_total=@mysql_num_rows($r=mysql_query(str_replace("<%limit_start%>", $limit_start, str_replace("<%limit%>", $item_per_page, $record_sql))));
$k=0;
for($i=0;$i<$this_page_total;$i++){
 $p=mysql_fetch_assoc($r);
 $status_class=$p["status"]=="paid"? "green" : ($p["status"]=="pending"? "orange" : "red");
 $his_row.="
 <tr class='row$k'>
  <td>".($i+1)."</td>
  <td class='number'>".number_format($p['amount'], 2)."</td>
  <td>".$r_payment_d[$p["payment_type"]]."<br />\n
      ".$p["acc_name"]."<br />\n
      ".$p["acc_no"]."
  </td>
  <td>".__("Requested").__(":")." ".date($vars["date_format"], strtotime($p["cdate"]))."<br />\n".
        __("Status").__(":")." <span class='bold $status_class'>".$r_status_d[$p["status"]]."</span><br />\n".
        __("Payment Date").__(":")." ".($p["status"]=="paid"? date($vars["date_format"], strtotime($p["payment_date"])) : __("N/A"))."<br />\n".
        __("Reference").__(":")." ".nl2br($p["payment_remark"])."</td>
  <td>".nl2br($p["remark"])."</td>
 </tr>";
 $k=1-$k;
}

//listing text
$listing_text=replace_tag(__("<%x%> <%title%> <%withdrawal%>."), array("<%x%>"=>"$total_record", "<%title%>"=>__($vars['ewallet_title']), "<%withdrawal%>"=>$total_record>1? __("withdrawals") : __("withdrawal")));

//listing
$his_list=
"<h2>".replace_tag(__("<%title%> Withdrawal History"), array("<%title%>"=>$point_title))."</h2>
$listing_text $nav_link
<table class='pbl_table'>
 <tr class='pbl_header'>
  <td>".__("ID")."</td>
  <td>".__("Amount")." ".__("(").$vars['currency'].__(")")."</td>
  <td>".__("Payment Info")."</td>
  <td>".__("Status")."</td>
  <td>".__("Remark")."</td>
 </tr>
 $his_row
</table>
$nav_link";

$content=$inc_wallet_select.$his_list;
print format_member_page($content, $this_title, $content_title, $css.$inc_jvscript);
?>